package com.aliyun.oss.utils;

import com.aliyun.oss.pojo.Message;
import com.aliyun.oss.pojo.Result;
import com.aliyun.oss.pojo.ResultMessage;
import com.fasterxml.jackson.databind.ObjectMapper;

public class MessageUtils {
//    将对象转换成json字符串
    public static String getMessage(boolean isSystemMessage,String fromName,Object message){
        ObjectMapper objectMapper = new ObjectMapper();
        ResultMessage resultMessage = new ResultMessage(isSystemMessage, fromName, message);
        String json = null;
        try {
            json = objectMapper.writeValueAsString(resultMessage);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

    public static Message jsonToMessage(String message) {
        ObjectMapper objectMapper = new ObjectMapper();
        Message message1 = null;
        try {
            message1 = objectMapper.readValue(message, Message.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return message1;
    }
}
